package com.jjc.android.dialog

import android.app.Activity
import android.app.Dialog
import com.github.gzuliyujiang.wheelpicker.OptionPicker
import com.jjc.android.util.px2dp
import com.lxj.xpopup.util.XPopupUtils

class BottomWheelDialog<T>(val context: Activity) {


    var titleText:String? = null
    var position:Int = 0
    lateinit var list:List<T>
    var onItemClick:((position:Int,value:T)->Unit)?=null
    fun title(title:String):BottomWheelDialog<T>{
        titleText = title
        return this
    }

    fun choosePosition(position:Int):BottomWheelDialog<T>{
        this.position = position
        return this
    }

    fun contentList(list:List<T>):BottomWheelDialog<T>{
        this.list = list
        return this
    }

    fun onItemClick(onItemClick:(position:Int,value:T)->Unit):BottomWheelDialog<T>{
        this.onItemClick = onItemClick
        return this
    }

    fun build(): CustomerWheelDialog{
        val picker = CustomerWheelDialog(context)
        picker.setTitle(titleText)
        picker.setBodyWidth(XPopupUtils.getScreenWidth(context).px2dp)
        picker.setData(list)
        picker.setDefaultPosition(position)
        picker.setOnOptionPickedListener { position, item ->
            onItemClick?.invoke(
                position,
                item as T
            )
        }
        return picker
    }

}